<template>
  <!-- Post.vue -->
  <div>
    <post-content :postProp="post" />
  </div>
</template>

<script>
import PostContent from '@/components/layout/PostContent.vue';
import { mapState } from 'vuex';

export default {
  created() {
    this.load(this.$route.params, 'created');
  },
  beforeRouteUpdate(to, from) {
    this.load(to.params, 'beforeRouteUpdate');
  },
  beforeRouteLeave(to, from) {
    if (/Post|Page/.test(to.name)) {
      this.load(to.params, 'beforeRouteLeave');
    }
  },
  computed: {
    ...mapState(['post']),
  },
  methods: {
    load(params, type = '') {
      params.id = params.slug;
      // this.$_log("[Post-Load]",params, type);
      this.$store.dispatch('getPost', params);
    },
  },
  components: {
    PostContent,
  },
};
</script>
